<template>
  <div class="containner">
    <el-card>
      <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <el-breadcrumb separator=">">
            <el-breadcrumb-item :to="{ path: '/' }">企业管理</el-breadcrumb-item>
            <el-breadcrumb-item><a href="/">岗位配置</a></el-breadcrumb-item>
          </el-breadcrumb>
        </div>
      </el-col>
    </el-row>
    </el-card>
    <!-- 公司名称和岗位名称 -->
    <el-row class="mc">
      <el-col :span="8">
        <div class="grid-content bg-purple">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="公司名称" prop="name">
              <el-select v-model="ruleForm.name" placeholder="请选择公司名称">
                <el-option label="公司一" value="shanghai"></el-option>
                <el-option label="公司二" value="beijing"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <el-col :span="10">
        <div class="grid-content bg-purple-light">
          <el-autocomplete v-model="state" :fetch-suggestions="querySearchAsync" placeholder="岗位名称"
            @select="handleSelect" clearable icon="el-icon-search"></el-autocomplete>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple">
          <el-button type="primary" size="small">模板导入</el-button>
          <el-button type="primary" size="small">导入岗位</el-button>
        </div>
      </el-col>
    </el-row>
    <!-- //岗位配置的标题 -->
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark peizhi">
          岗位配置
        </div>
      </el-col>
    </el-row>
    <!-- //岗位配置的表格 -->
    <!-- <el-row>
      <el-col :span="18">
        <div class="grid-content bg-purple-dark peizhi">
          <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
            @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column label="岗位名称">
              <template slot-scope="scope">{{ scope.row.date }}</template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple-dark peizhi">
          <el-table>
            <el-table-column prop="name" label="操作">
              <el-button  type="primary" size="mini">授权</el-button>

            </el-table-column>
          </el-table>
        </div>
      </el-col>
    </el-row> -->
    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width:100%"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column label="岗位名称" style="width:80%">
        <template slot-scope="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column prop="name" label="操作" style="width:20%">
        <el-button type="primary" icon="el-icon-edit" size="mini">编辑</el-button>
        <el-button type="danger" icon="el-icon-delete" size="mini">删除</el-button>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      },
      restaurants: [],
      state: '',
      timeout: null,
      tableData: [
        {
          date: '2016-05-03',
          name: '王小虎'
        },
        {
          date: '2016-05-02',
          name: '王小虎'
        },
        {
          date: '2016-05-04',
          name: '王小虎'
        },
        {
          date: '2016-05-01',
          name: '王小虎'
        }
      ]
    }
  },
  methods: {
    loadAll() {
      return [
        { value: '三全鲜食（北新泾店）', address: '长宁区新渔路144号' },
        {
          value: 'Hot honey 首尔炸鸡（仙霞路）',
          address: '上海市长宁区淞虹路661号'
        },
        {
          value: '浮生若茶（凌空soho店）',
          address: '上海长宁区金钟路968号9号楼地下一层'
        },
        { value: 'NONO JUICE  鲜榨果汁', address: '上海市长宁区天山西路119号' },
        { value: 'CoCo都可(北新泾店）', address: '上海市长宁区仙霞西路' }
      ]
    },
    querySearchAsync(queryString, cb) {
      var restaurants = this.restaurants
      var results = queryString
        ? restaurants.filter(this.createStateFilter(queryString))
        : restaurants

      clearTimeout(this.timeout)
      this.timeout = setTimeout(() => {
        cb(results)
      }, 500 * Math.random())
    },
    createStateFilter(queryString) {
      return state => {
        return (
          state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        )
      }
    },
    handleSelect(item) {
      console.log(item)
    },
    //表格的函数
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  },
  mounted() {
    this.restaurants = this.loadAll()
  }
}
</script>
<style lang="less" scoped>
.mc {
  padding-top: 10px;
}
.peizhi {
  font-size: 17px;
  height: 50px;
  line-height: 50px;
  color: #58a3f7;
  background-color: #e7effc;
}
</style>